package com.fyzk.adapter;

import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.fyzk.activity.lottery.recommend_order.MyRecommendOrderBean;
import com.fyzk.utils.SpanUtils;
import com.fyzk.utils.StringUtils;
import com.tyjc.lottery.R;

import java.text.DecimalFormat;

import http.DataUtil.text.TextUtil;

/**
 * Created by Administrator on 2018/9/25.
 */

public class DocumentaryAdapter extends BaseQuickAdapter<MyRecommendOrderBean, BaseViewHolder> {

    public DocumentaryAdapter() {
        super(R.layout.item_documentary);
    }

    @Override
    protected void convert(BaseViewHolder helper, MyRecommendOrderBean item) {
        Glide.with(mContext).load(item.getUserPhotoUrl())
                .circleCrop()
                .error(R.drawable.rr_header_icon)
                .placeholder(R.drawable.rr_header_icon)
                .into((ImageView) helper.getView(R.id.iv_avatar));
        boolean isBasketball = true;//是否篮球
        String lotteryTypeName = "";//玩法
        String evenRedName = "";
        switch (item.getLotteryType()) {
            case 3001://竞彩篮球胜负
                lotteryTypeName = "胜负";
                isBasketball = true;
                break;
            case 3002://竞彩篮球让分胜负
                lotteryTypeName = "让分胜负";
                isBasketball = true;
                break;
            case 3003://竞彩篮球胜分差
                lotteryTypeName = "胜分差";
                isBasketball = true;
                break;
            case 3004://竞彩篮球大小分
                lotteryTypeName = "大小分";
                isBasketball = true;
                break;
            case 3005://竞彩篮球混合过关
                lotteryTypeName = "混合";
                isBasketball = true;
                break;
            case 3006://竞彩足球让球胜平负
                lotteryTypeName = "让球胜平负";
                isBasketball = false;
                break;
            case 3007://竞彩足球比分
                lotteryTypeName = "比分";
                isBasketball = false;
                break;
            case 3008://竞彩足球总进球数
                lotteryTypeName = "总进球";
                isBasketball = false;
                break;
            case 3009://竞彩足球半全场胜平负
                isBasketball = false;
                lotteryTypeName = "半全场";
                break;
            case 3010://竞彩足球胜平负
                lotteryTypeName = "胜平负";
                isBasketball = false;
                break;
            case 3011://竞彩足球混合过关
                lotteryTypeName = "混合";
                isBasketball = false;
                break;
        }
        if (item.getEvenRed() == 1) {
            evenRedName = "红";
        } else if (item.getEvenRed() > 1) {
            evenRedName = item.getEvenRed() + "连红";
        }
        helper.setText(R.id.tv_name, item.getUserName())
                .setText(R.id.tv_play_name, lotteryTypeName + item.getPlayName())
                .setText(R.id.tv_session, evenRedName)
                .setImageResource(R.id.iv_lottery_type, isBasketball ?
                        R.drawable.icon_basketball :
                        R.drawable.icon_football)
                .setGone(R.id.tv_session, item.getEvenRed() > 0)
                .setGone(R.id.tv_play_name, !TextUtil.isEmpty(item.getPlayName()))
                .setGone(R.id.iv_hot1, item.getFollowTotalNumber() >= 1)
                .setGone(R.id.iv_hot2, item.getFollowTotalNumber() >= 4)
                .setGone(R.id.iv_hot3, item.getFollowTotalNumber() >= 7);

        if ("0".equals(item.getIsShowMaxSP()) && item.getMaxSp() > 0) {
            helper.setGone(R.id.tv_maxSp, true);
            helper.setText(R.id.tv_maxSp, "最高SP：" + String.valueOf(item.getMaxSp()));
        } else {
            helper.setGone(R.id.tv_maxSp, false);
        }

        SpanUtils.with(helper.getView(R.id.tv_follow_total_amount))
                .appendLine("单倍金额")
                .setFontSize(14, true)
                .setForegroundColor(mContext.getResources().getColor(R.color.color_999999))
                .append(new DecimalFormat("#0.00").format(item.getStartingAmount()) + "米")
                .setFontSize(13, true)
                .setForegroundColor(mContext.getResources().getColor(R.color.color_1c1c1c))
                .create();
        SpanUtils.with(helper.getView(R.id.tv_buy_self))
                .appendLine("发单人自购")
                .setFontSize(14, true)
                .setForegroundColor(mContext.getResources().getColor(R.color.color_999999))
                .append(String.format("%s米", new DecimalFormat("#0.00").format(item.getAmount() / 100)))
                .setFontSize(13, true)
                .setForegroundColor(mContext.getResources().getColor(R.color.color_1c1c1c))
                .create();
        SpanUtils.with(helper.getView(R.id.tv_multi))
                .appendLine("方案倍数")
                .setFontSize(14, true)
                .setForegroundColor(mContext.getResources().getColor(R.color.color_999999))
                .append(String.format("%s倍", (int) ((item.getAmount() / item.getStartingAmount()) / 100)))
                .setFontSize(13, true)
                .setForegroundColor(mContext.getResources().getColor(R.color.color_1c1c1c))
                .create();

        helper.setText(R.id.tv_describe, item.getMemo());
        helper.setText(R.id.tv_cut_off_date, String.format("%s  截止：%s", isBasketball ?
                        mContext.getString(R.string.jclq) :
                        mContext.getString(R.string.jcz),
                item.getEndTime()));
        helper.addOnClickListener(R.id.iv_avatar);
        helper.addOnClickListener(R.id.tv_made_the_documentary);
    }


}
